package com.hsyt.pms.api.vo.system;

import com.hsyt.pms.api.entity.system.SysDictionary;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;

/**
 * @Description: TODO
 * @author wangze@hsyuntai.com
 * @date 2019年2月12日 下午2:45:51
 */
public class SysDictionaryVo extends SysDictionary {

    public static String getComboDataFromDictList(List<SysDictionaryVo> sysDictList, String selectValue) {
        StringBuilder resultStr = new StringBuilder("[[\'" + selectValue + "\', \'--选择--\'],");
        if (CollectionUtils.isEmpty(sysDictList)) {
            return "[[\'" + selectValue + "\', \'--选择--\']]";
        } else {
            for (int i = 0; i < sysDictList.size(); i++) {
                SysDictionaryVo dto = sysDictList.get(i);
                resultStr.append("[\'");
                resultStr.append(dto.getDictCode());
                resultStr.append("\',\'");
                resultStr.append(dto.getDictName());
                resultStr.append("\']");
                if (i != sysDictList.size() - 1) {
                    resultStr.append(",");
                }
            }
            resultStr.append("]");
        }
        return resultStr.toString();
    }

    public static String getComboData(List<SysDictionaryVo> sysDictList, String selectValue) {
        StringBuilder returnStr = new StringBuilder("[[\'").append(selectValue).append("\', \'--请选择--\'],");
        if (sysDictList == null || sysDictList.isEmpty()) {
            return "[[\'" + selectValue + "\', \'--请选择--\']]";
        } else {
            for (int i = 0; i < sysDictList.size(); i++) {
                SysDictionaryVo dto = sysDictList.get(i);
                returnStr.append("[\'");
                returnStr.append(dto.getDictCode());
                returnStr.append("\',\'");
                returnStr.append(dto.getDictName());
                returnStr.append("\']");
                if (i != sysDictList.size() - 1) {
                    returnStr.append(",");
                }
            }
            returnStr.append("]");
        }
        return returnStr.toString();
    }

}
